{include file="public/head"/}
<style>
  .main-content {
    margin-left: 0px;
    min-height: 80%;
  }

  .row .cf {
    margin-bottom: 10px;
  }
</style>


<div class="main-container" id="main-container">
  <script type="text/javascript">
    try {
      ace.settings.check('main-container', 'fixed')
    } catch (e) {
    }
  </script>

  <div class="main-container-inner">
    <a class="menu-toggler" id="menu-toggler" href="#">
      <span class="menu-text"></span>
    </a>
    {include file="public/nav"/}

    <div class="main-content">
      <div class="page-content">
        <div class="row">
          <div class="well">
            <h1 class=" lighter smaller">
              <span class="blue bigger-125">
                <i class="ace-icon fa fa-navicon"></i>
              </span>
              历史工单
              <a style="font-size:13px;" href="{:url('main/modulefront')}">返回首页</a>
            </h1>
            <hr>
            <div class="space"></div>

            <div class="row-fluid">
              <!--<h3 class="lighter block green">选择或添加客户信息</h3>-->
              <!--<a class="btn btn-info" href="#modal-fmWork" data-toggle="modal">
                <i class="icon-ok bigger-110"></i>
                添加客户
              </a>-->
              <!--数据筛选表单-->
              <form class="form-inline fmWorkQuery-hook">
                <input class="input-small" name="num" placeholder="工单号"/>
                <input class="input-large" name="car_num" placeholder="车牌号"/>
                <input class="input-small" name="client_name" placeholder="客户姓名"/>
                <button type="button" class="btn btn-info btn-sm" onclick="indexInvoice.search();">
                  <i class="fa fa-search bigger-110"></i>
                  查找
                </button>
                <button type="button" class="btn btn-primary btn-sm" onclick="indexInvoice.searchNull();">
                  <i class="fa fa-remove bigger-110"></i>
                  清空
                </button>
              </form>
              <!--客户数据表-->
              <table id="tbWork"></table>
              <!--客户表页码内容-->
              <div id="tbWorkPager"></div>

              <!--结账模态框-->
              <div id="modal-fmWorkPay" class="modal" tabindex="-1">
                <div class="modal-dialog">
                  <div class="modal-content">
                    <div class="modal-header">
                      <button type="button" class="close" data-dismiss="modal">&times;</button>
                      <h4 class="blue bigger">结账</h4>
                    </div>
                    <div class="modal-body overflow-visible">
                      <!--添加客户表单-->
                      <form class="form-horizontal" id="fmWorkPay" method="post">
                        <input type="hidden" name="id" value="">
                        <div class="form-group">
                          <label class="col-sm-3 control-label no-padding-right">总计</label>
                          <div class="col-sm-9">
                            <input name="total" class="col-xs-10 col-sm-5" value="" readonly>
                            <span class="help-inline col-xs-12 col-sm-7">
                      <span class="middle"></span>
                    </span>
                          </div>
                        </div>
                        <div class="form-group">
                          <label class="col-sm-3 control-label no-padding-right"> 结账方式 </label>
                          <div class="col-sm-9">
                            <div class="radio">
                              <label>
                                <input name="pay_type" type="radio" class="ace" value="微信">
                                <span class="lbl">微信</span>
                              </label>&nbsp;&nbsp;
                              <label>
                                <input name="pay_type" type="radio" class="ace" value="支付宝">
                                <span class="lbl">支付宝</span>
                              </label>&nbsp;&nbsp;
                              <label>
                                <input name="pay_type" type="radio" class="ace" value="现金">
                                <span class="lbl">现金</span>
                              </label>&nbsp;&nbsp;
                              <label>
                                <input name="pay_type" type="radio" class="ace" value="刷卡">
                                <span class="lbl">刷卡</span>
                              </label>
                            </div>
                            <span class="help-inline col-xs-12 col-sm-7">
                      <span class="middle"></span>
                    </span>
                          </div>
                        </div>
                      </form>
                    </div>

                    <div class="modal-footer">
                      <button class="btn btn-sm" data-dismiss="modal">
                        <i class="icon-remove"></i>
                        取消
                      </button>
                      <button class="btn btn-sm btn-primary" onclick="indexInvoice.doPay(this);" data-loading-text="保存中...">
                        <i class="icon-ok"></i>
                        保存
                      </button>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <hr>
            <div class="space"></div>
          </div>
        </div><!-- /.row -->
      </div><!-- /.page-content -->
    </div><!-- /.main-content -->

  </div><!-- /.main-container-inner -->

  <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
    <i class="icon-double-angle-up icon-only bigger-110"></i>
  </a>
</div>
<!-- /.main-container -->
{include file="public/footerjs"/}

<script>
  $(function () {
    //加载数据
    var $tbWork = $('#tbWork'), $pager = $('#tbWorkPager');
    $tbWork.jqGrid({
      url: "{:url('work/getPayedWorkList')}",
      datatype: 'json',
      mttype: 'post',
      colNames: ['工单号', '车牌号', '客户', '接待人','操作'],
      colModel: [
        {name: 'num', index: 'num', width: '100', align: 'center'},
        {name: 'car_num', index: 'car_num', width: '100', align: 'center'},
        {name: 'client_name', index: 'client_name', width: '100', align: 'center'},
        {name: 'reception_name', index: 'reception_name', width: '100', align: 'center'},
        {
          name: 'id', index: 'id', width: '100', align: 'center',
          formatter: function (value, options, obj) {
            var res='<a href="/admin/invoice/index/id/'+value+'" target="_blank" style="cursor:pointer;">详细信息</a>';
            return res;
          }
        },
      ],
      height: 'auto',
      pager: '#tbWorkPager',
      viewrecords: true,
      rowNum: 10,
      rowList: [10, 20, 40],
      autowidth: true
    });

    // 隐藏水平方向滚动条
    $tbWork.closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
  });
  indexInvoice = {
    search: function () {
      var $fmQuery = $('.fmWorkQuery-hook');
      var param = ittaoli.serializeObject($fmQuery);
      $('#tbWork').jqGrid('setGridParam', {
        postData: {q: JSON.stringify(param)},
        page: 1
      }).trigger("reloadGrid");
    },
    searchNull: function () {
      $('.fmWorkQuery-hook input').val('');
      var param = {};
      $('#tbWork').jqGrid('setGridParam', {
        postData: {q: JSON.stringify(param)},
        page: 1
      }).trigger("reloadGrid");
    },
    pay:function (id,total){
      $('#modal-fmWorkPay').modal('show');
      $('#fmWorkPay input[name=id]').val(id);
      $('#fmWorkPay input[name=total]').val(total);
    },
    doPay:function(obj){
      var param=ittaoli.serializeObject($('#fmWorkPay'));
      if(!param.pay_type){
        bootbox.alert('请选择支付方式！');
        return;
      }
      $(obj).button('loading');
      $.post('{:url("work/doPay")}',{param:JSON.stringify(param)},function(data){
        if (data > 0) {
          bootbox.alert("结账成功！");
          $('#modal-fmWorkPay').modal('hide');
          $('#btnPay'+param.id).remove();

        } else {
          bootbox.alert('结账失败！');
        }
        $(obj).button('reset');
      })
    }
  };
</script>

{include file="public/foot"/}
